#ifndef SCRIPT_H
#define SCRIPT_H

#include <string>
#include <list>
#include "Demo.h"

class ScriptPoint
{
public:
	ScriptPoint() {};
	ScriptPoint(float Time, float Origin[3], float Angles[3]);

	float GetTime() {return m_Time;};
	float GetOrigin(int Index) {return m_Origin[Index];};
	float GetAngle(int Index) {return m_Angles[Index];};

	void SetTime(float Time) {m_Time = Time;};

	bool WriteTo(FILE* f);
	bool LoadFrom(FILE* f);
private:
	float m_Time;
	float m_Origin[3];
	float m_Angles[3];
};

class ScriptSegment
{
public:
	ScriptSegment() {};
	ScriptSegment(ScriptPoint From,ScriptPoint To);
	void Interpolate(float Time,float Origin[3],float Angles[3]);
	void SetFrom(ScriptPoint From) {m_From = From;};
	void SetTo(ScriptPoint To) {m_To = To;};

	float GetFromTime() {return m_From.GetTime();};
	float GetToTime() {return m_To.GetTime();};

	ScriptPoint& GetTo() {return m_To;};
	ScriptPoint& GetFrom() {return m_From;};

	bool WriteTo(FILE* f);
	bool LoadFrom(FILE* f);
	float GetRatio(float time);
private:
	ScriptPoint m_From;
	ScriptPoint m_To;
};


class Script  
{
public:
	Script();
	~Script();
	bool Load(std::string Filename);
	bool Save(std::string Filename);
	void CreateDefault(Demo& D);

	void UpdateCamera(float Time,float Origin[3],float Angles[3]);
	void SetPoint(float Time,float Origin[3],float Angles[3]);
	void RemovePoint(float Time);

	void GotoPrevTime(float& time);
	void GotoNextTime(float& time);

	float GetRatio(float time);

	bool IsPoint(float Time);
private:
	typedef std::list<ScriptSegment> SegList;
	SegList							m_Segments;
};

#endif 
